package com.zx.viewlearn.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.zx.viewlearn.R;

import java.util.ArrayList;
import java.util.List;

public class ViewLearnActivity19PullToRefresh_2 extends AppCompatActivity {
    RecyclerView content_rv;
    RecyclerView.Adapter adapter;
    RecyclerView.LayoutManager layoutManager;
    final List<String> list = new ArrayList<>();

    class MYViewHolder extends RecyclerView.ViewHolder {

        TextView name_tv;

        public MYViewHolder(View itemView) {
            super(itemView);
            name_tv = itemView.findViewById(R.id.name_tv);
        }

        public void setName(String name) {
            if (name_tv != null) name_tv.setText(name);
        }

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_view_learn_activity19_pull_to_refresh_2);
        content_rv = findViewById(R.id.content_rv);
        adapter = new RecyclerView.Adapter<MYViewHolder>() {

            @Override
            public MYViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
//                View view = getLayoutInflater().inflate(R.layout.item_19, null);
                View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_19, parent,
                        false);
                MYViewHolder mViewHolder = new MYViewHolder(view);
                return mViewHolder;
            }

            @Override
            public void onBindViewHolder(MYViewHolder holder, int position) {
                holder.setName(list.get(position));
            }

            @Override
            public int getItemCount() {
                return list.size();
            }
        };
        layoutManager = new LinearLayoutManager(this);
        content_rv.setLayoutManager(layoutManager);
        for (int i = 0; i < 20; i++) {
            list.add("name---" + i);
        }
        content_rv.setAdapter(adapter);
    }
}
